package com.winfar.ic.helper;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import android.content.Context;

public class FileDataHelper implements FileDataInterface {
	private Context context;

	private String FILESPATH;

	public FileDataHelper(Context context) {
		this.context = context;
		File file = this.context.getFilesDir();
		FILESPATH = file.getPath() + "\\";
	}

	@Override
	public File creatDataFile(String fileName) throws IOException {
		return FileHelper.creatFile(FILESPATH + fileName);
	}

	@Override
	public File creatDataDir(String dirName) {
		return FileHelper.creatDir(FILESPATH + dirName);
	}

	@Override
	public boolean delDataFile(String fileName) {
		return FileHelper.delFile(FILESPATH + fileName);
	}

	@Override
	public boolean delDataDir(String dirName) {
		return FileHelper.delFile(FILESPATH + dirName);
	}

	@Override
	public boolean renameDataFile(String oldName, String newName) {
		return FileHelper.renameFile(FILESPATH + oldName, FILESPATH + newName);
	}

	@Override
	public boolean copyDataFileTo(String srcFileName, String destFileName)
			throws IOException {
		return FileHelper.copyFileTo(FILESPATH + srcFileName, FILESPATH
				+ destFileName);
	}

	@Override
	public boolean copyDataFilesTo(String srcDirName, String destDirName)
			throws IOException {
		return FileHelper.copyFilesTo(FILESPATH + srcDirName, FILESPATH
				+ destDirName);
	}

	@Override
	public boolean moveDataFileTo(String srcFileName, String destFileName)
			throws IOException {
		return FileHelper.moveFileTo(FILESPATH + srcFileName, FILESPATH
				+ destFileName);
	}

	@Override
	public boolean moveDataFilesTo(String srcDirName, String destDirName)
			throws IOException {
		return FileHelper.moveFilesTo(FILESPATH + srcDirName, FILESPATH
				+ destDirName);
	}

	@Override
	public void wirteFile(String fileName, String content) throws IOException {
		OutputStream os = context.openFileOutput(fileName,
				Context.MODE_WORLD_WRITEABLE);
		FileHelper.writeFile(os, content);
	}

	@Override
	public void appendFile(String fileName, String content) throws IOException {
		OutputStream os = context.openFileOutput(fileName, Context.MODE_APPEND);
		FileHelper.writeFile(os, content);
	}

	@Override
	public byte[] readFile(String fileName) throws IOException {
		InputStream is = context.openFileInput(fileName);
		return FileHelper.readFile(is);
	}
}
